﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using BakalarskaPraca.Generation.Data;
using Microsoft.DirectX;

namespace BakalarskaPraca.Generation.Tasks
{
    public class GridPositionPlantDistributionGeneration : PlantDistributionGenerationBase
    {
        public int GridSize;
        public int Variance;

        public GridPositionPlantDistributionGeneration(List<HumidityPolygon> polygons, ModelData modelData)
            : base(polygons, modelData)
        {
            this.GridSize = 20;
            this.Variance = 30;
        }

        protected override string Name
        {
            get { return "Creating plants grid"; }
        }

        protected override void Populate()
        {
            this.Plants = new List<Plant>();
            int width = this.GetBounds().X;
            int height = this.GetBounds().Y;
            for (int x = 0; x < (width / this.GridSize); x++)
            {
                for (int y = 0; y < (height / this.GridSize); y++)
                {
                    int varX = this.RandomGenerator.Next(Variance * 2) - Variance;
                    int varY = this.RandomGenerator.Next(Variance * 2) - Variance;

                    Plant plant = this.PlantSeed(x * this.GridSize + varX, y * this.GridSize + varY);
                    if (plant != null)
                    {
                        this.Plants.Add(plant);
                    }
                }
                this.Reporter.ReportProgress(x, width / this.GridSize);
            }
        }
    }
}